<template>
  <main>
    <el-table
      :data="memberList.slice((currentPage-1)*pagesize,currentPage*pagesize)"
      border
      style="width: 100%;border:1px solid #00BDAC;"
        height="95%"
      :header-cell-style="{borderRight:'none',backgroundColor:'#00BDAC',color:'#FFFFFF'}"
    >
      <el-table-column align="center" type="index" :index="table_index"  width="50px" label="序号"></el-table-column>
      <el-table-column align="center" prop="u_name" width="100px" label="姓名"></el-table-column>
      <el-table-column align="center" prop="u_tel"  label="联系电话"></el-table-column>
      <el-table-column align="center" prop="u_address" label="居住地址"></el-table-column>
      <el-table-column align="center" prop="u_post"  label="目前岗位"></el-table-column>
      <el-table-column align="center" prop="u_account" label="系统账号"></el-table-column>
      <!--<el-table-column align="center" label="管理" >
        <template slot-scope="scope">
          <el-button size="mini" class="greenButton" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" v-show="shickid != scope.row.u_id" class="pinkButton" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          <el-button type="warning" size="mini" v-show="shickid == scope.row.u_id">本人账号</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-size="pagesize"
      layout="total,prev, pager, next, jumper"
      :total="memberList.length"
      prev-text="上一页"
      next-text="下一页"
    ></el-pagination>

    <el-dialog destroy-on-close :visible.sync="isShowEdit" :show-close="false" class="edit-dialog" width="1100px">
         <div slot="title" class="edit-dialog-title">编辑巡查更人员信息</div>
      <el-form :model="memberInfo" class="edit-form" label-width="100px" label-position="left">
        <el-form-item label="姓　　名：">
          <el-input class="add-input" v-model="memberInfo.u_name" placeholder="请输入姓名"></el-input>
        </el-form-item>
         <el-form-item label="工　　号：">
          <el-input class="add-input" v-model="memberInfo.u_account" placeholder="请输入工号"></el-input>
        </el-form-item>
       
        <el-form-item label="年　　龄：">
          <el-input class="add-input" v-model="memberInfo.u_age" placeholder="请输入年龄"></el-input>
        </el-form-item>
        <el-form-item label="居住地址：">
          <el-input class="add-input" v-model="memberInfo.u_address" placeholder="请输入地址"></el-input>
        </el-form-item>
        <el-form-item label="目前岗位：">
          <el-input class="add-input" v-model="memberInfo.u_post" placeholder="请输入目前岗位"></el-input>
        </el-form-item>
        <el-form-item label="联系电话：">
          <el-input class="add-input" v-model="memberInfo.u_tel" placeholder="请输入联系电话"></el-input>
        </el-form-item>
        <el-form-item label="设置密码：">
          <el-input class="add-input" v-model="memberInfo.u_pass" placeholder="请输入密码"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer">
        <el-button @click="cancel" class="pinkButton" type="primary">取消</el-button>
        <el-button @click="submit" class="greenButton" type="primary">提交</el-button>
      </div>
    </el-dialog>
  </main>
</template>

<script>

export default {
  data: function() {
    return {
      shickid:localStorage.getItem('uid'),
      currentPage:1,
      pagesize:10,
      memberList: [],
      isShowEdit: false,
      memberInfo: {
        u_name: "",
        u_tel: "",
        u_age: "",
        u_address: "",
        u_post: "",
        u_account: "",
        u_pass: ""
      }
    };
  },
  mounted(){
   this.huoqu();
  },

  methods: {
     table_index(index){
        return (this.currentPage -1) * this.pagesize + index + 1
    },  
    huoqu(){
      this.ajaxCommon.ajax({
                    url: 'WXuserlist',
                    success: (res) => {
                      console.log(res)
                        this.memberList = res;
                      
                     
                    }
                });
    
    },
    handleCurrentChange(val){
      this.currentPage = val;
    },
    handleEdit(index, row) {
        this.isShowEdit = true;
        row.u_pass = "";
        this.memberInfo = row;
    },
    handleDelete(index, row) {
      
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           let parme = {
            u_id:row.u_id
          }
       this.ajaxCommon.ajax({
                    url: 'WXuserdelete',
                    data:parme,
                    success: (res) => {
                      console.log(res)
                      if(res.code == 200){
                        this.$message({
                            message: '删除成功',
                            type: 'success',
                            duration:'2000'
                          });
                          this.huoqu();

                      }else{
                        this.$message({
                            message: res.status,
                            type: 'error',
                            duration:'2000'
                          });

                      }
                     
                    }
                });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });

    },

    submit(){
      if(this.memberInfo.u_tel == ''){
        this.$message({
                            message: '请输入手机号',
                            type: 'error',
                            duration:'2000'
                          });
                          return
           
      }else if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.memberInfo.u_tel))){
        this.$message({
                            message: '手机号格式不对',
                            type: 'error',
                            duration:'2000'
                          });
                          return

      }else if(this.memberInfo.u_account == ''){
        this.$message({
                            message: '请输入工号',
                            type: 'error',
                            duration:'2000'
                          });
                          return
                          
      }else if(this.memberInfo.u_name == ''){
        this.$message({
                            message: '请输入姓名',
                            type: 'error',
                            duration:'2000'
                          });
                          return                         
      
      }else if(this.memberInfo.u_pass == ''){
        this.$message({
                            message: '请输入密码',
                            type: 'error',
                            duration:'2000'
                          });
                          return

      }else{
      
      this.ajaxCommon.ajax({
                    url: 'WXuserupdate',
                    method:'post',
                    data:this.memberInfo,
                    success: (res) => {
                      console.log(res)
                      if(res.code == 200){
                        this.$message({
                            message: '修改成功',
                            type: 'success',
                            duration:'2000'
                          });
                          this.huoqu();
                          this.isShowEdit = false;
                      }else{
                         this.$message({
                            message: res.status,
                            type: 'success',
                            duration:'2000'
                          });
                      }
                     
                    }
                });
      }

      
    },
    cancel(){
      this.isShowEdit = false;
    }
  }
};
</script>

<style lang="less" scoped>
main {
  width: 100%;

  .edit-dialog-title {
    color: #ffffff;
    padding-left: 30px;
    height: 36px;
    line-height: 36px;
    font-size: 14px;
    background: #00bdac;
  }

  .add-input {
    width: 260px;
  }

  .edit-form {
    width: 100%;
  }

  .footer {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
  }
}
</style>

<style lang="less">
main {
  .edit-dialog {
    .el-dialog__header {
      padding: 0;
    }

    .el-dialog__body {
      padding: 30px;
      height: 450px;
      overflow: auto;
    }
  }
}
</style>
